package com.zxp.common.codegen.pojo;


import cn.hutool.core.util.StrUtil;
import lombok.Getter;
import lombok.Setter;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * [path1]	1级包名	com
 * [path2]	2级包名	qingcheng
 * [path3]	3级包名	goods
 * [pathn]	n级包名 n是具体的数字
 * [path_all]	包名转目录	com/qingcheng/goods
 *
 */
@Getter @Setter
public class Settings {

    /**
     * 工程英文名称
     */
    private String project="zxpdemo"; // 项目名

    /**
     * 包名，至少需要3级, 如： com.qingcheng.goods
     */
    private String pPackage="com.zxp.zxpdemo";

    /**
     * 工程中文名称
     */
    private String projectComment;

    /**
     * 工程建立者
     */
    private String author;

    public Settings(String project, String pPackage, String projectComment, String author) {

        if(StrUtil.isNotBlank(project)) {
            this.project = project;
        }
        if(StrUtil.isNotBlank(pPackage)) {
            this.pPackage = pPackage;
        }
        this.projectComment = projectComment;
        this.author = author;
    }

    public Map<String, Object> getSettingMap(){
        Map<String, Object> map = new HashMap<>();
        Field[] declaredFields = Settings.class.getDeclaredFields();
        for (Field field : declaredFields) {
            field.setAccessible(true);
            try{
                map.put(field.getName(), field.get(this));
            }catch (Exception e){}
        }

        String[] paths = pPackage.split("\\.");
        for (int i = 1; i <= paths.length; i++) {
            map.put("path"+i, paths[i-1]);
        }
        map.put("pathAll", StrUtil.replace(pPackage,".","/"));
        return map;
    }

}
